<template>


  <el-row class="home" :gutter="20">
    <el-col :span="8" style="margin-top:20px">
      <el-card class="box-card" shadow="hover">
        <div slot="header" class="clearfix">
          <span><img :src="userimg" alt=""></span>
          <div class="userinfo">
            <p class="name">Admin</p>
            <p class="access">超级管理员</p>

          </div>
        </div>
        <div class="text-item">
          <p>上次登录时间:<span>2022-07-16</span></p>
          <p>上次登录地点:<span>广东</span></p>
        </div>
      </el-card>
      <el-card style="margin-top: 20px;  height: 400px;">
        <el-table :data="tableitem" style="width: 100%" :default-sort="{ prop: 'date', order: 'descending' }">
          <el-table-column prop="name" :label="tablehead.name">
          </el-table-column>
          <el-table-column prop="today" :label="tablehead.today" sortable>
          </el-table-column>
          <el-table-column prop="mouthbuy" :label="tablehead.mouthbuy" sortable>
          </el-table-column>
          <el-table-column prop="totalbuy" :label="tablehead.totalbuy" sortable>
          </el-table-column>

        </el-table>
      </el-card>



    </el-col>
    <el-col class="numbox" :span="16" style="margin-top:20px">
      <div class="num">
        <el-card class="card" v-for="item in countdata " :key="item.name" :body-style="{ display: 'flex', padding: 0 }">
          <i class="icon" :class="`el-icon-${item.icon}`" :style="{ background: item.color }"></i>
          <div class="detail">
            <p class="numm">${{ item.value }}</p>
            <p class="text">{{ item.name }}</p>
          </div>
        </el-card>
      </div>

      <el-card style="height: 330px;">
        <echa style="height: 330px;" :chartData="echartdata.order"></echa>
      </el-card>

      <div class="graph">
        <el-card class="graph-card1" style="height: 260px;">

          <echa style="height: 240px; " :chartData="echartdata.user"> </echa>

        </el-card>

        <el-card class="graph-card2" style="height: 260px;" >

          <echa style="height: 240px; " :chartData="echartdata.vide" :isAxisChart="false"> </echa>
        </el-card>
      </div>


    </el-col>
  </el-row>

</template>

<script>
import { getData } from '../../../api/data.js';
// import * as echarts from 'echarts';
import echa from '../../components/Echart.vue';

export default {
  name: 'MagementHome',

  components: {
    echa
  },
  data() {
    return {
      userimg: require('@/assets/head.png'),
      tableitem: [],
      tablehead: {
        name: '课程',
        today: '今日购买',
        mouthbuy: '本月购买',
        totalbuy: '总购买'
      },
      countdata: [
        {
          name: '今日支付订单',
          value: 1234,
          icon: "success",
          color: "#2ec7c9"

        },
        {
          name: '今日收藏订单',
          value: 1234,
          icon: "star-on",
          color: "#ffb980"

        },
        {
          name: '今日未支付订单',
          value: 1234,
          icon: "s-goods",
          color: "#2ec7c9"

        },
        {
          name: '本月支付订单',
          value: 1234,
          icon: "success",
          color: "#2ec7c9"

        },
        {
          name: '本月收藏订单',
          value: 1234,
          icon: "star-on",
          color: "#ffb980"

        },
        {
          name: '本月未支付订单',
          value: 1234,
          icon: "s-goods",
          color: "#2ec7c9"

        },
      ],
      echartdata: {
        order: {
          Xdata: [],
          series: []
        },
        user: {
          Xdata: [],
          series: []
        },
        vide: {
           series: []
        }
          
           
          
        
      }

    };
  },
  created() {

  },
  mounted() {
    getData().then(res => {
      console.log(res);
      const { code, data } = res.data
      if (code === 2000) {
        this.tableitem = data.tableitem
        const order = data.orderdata
        // console.log("order数据");
        // console.log(order);
        const xData = order.date
        console.log("xData数据");
        console.log(xData);
        const keyArray = Object.keys(order.data[0])
        const series = []
        keyArray.forEach(key => {
          series.push({
            name: key,
            data: order.data.map(item => item[key]),
            type: 'line'

          })
        })
        // 折线图


        this.echartdata.order.Xdata = xData
        this.echartdata.order.series = series


        //柱状图

        this.echartdata.user.Xdata = data.userData.map(item => item.data)
        this.echartdata.user.series = [
          {
            name: '新增用户',
            data: data.userData.map(itme => itme.new),
            type: 'bar'

          },
          {
            name: '活跃用户',
            data: data.userData.map(itme => itme.active),
            type: 'bar'

          },

        ]

        //饼图

        this.echartdata.vide.series = [
          {
            data:data.videoData,
            type:'pie'
          }
        ]

      }
    })
  },

  methods: {

  },
};
</script>

<style lang="less" scoped>
.clearfix {
  width: 60%;
  height: 200px;
  display: flex;
  justify-content: space-between;
  align-items: center;

  img {
    width: 100px;
    height: 100px;
    border-radius: 50%;
  }



}

.box-card {
  .text-item {
    span {
      // display: inline-block;
      margin-left: 20px;
    }
  }

  .el-table {
    margin-top: 20px;
    height: 460px;
    padding: 0;
  }

  .el-card {
    margin-left: 10px;
  }
}

.numbox {
  .num {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    justify-items: space-between;
    align-items: center;

    .card {
      flex: 0 0 30%;
      height: 70px;
      margin-left: 20px;
      margin-bottom: 20px;


      .icon {
        width: 100px;
        height: 70px;
        line-height: 70px;
        text-align: center;
        font-size: 30px;

      }

      .detail {
        width: 150px;
        height: 70px;

        p {
          margin: 0;
        }

        .numm {
          margin-top: 10px;
          font-size: 20px;
        }
      }
    }
  }

  .graph {
    display: flex;
    flex-direction: row;

    .graph-card1 {
      margin-top: 10px;
      margin-right: 20px;
      flex: 1;
    }

    .graph-card2 {
      margin-top: 10px;
      margin-left: 20px;
      flex: 1;
    }
  }
}
</style>